namespace SmartSoft.Controls
{
    using SmartSoft;
    using SmartSoft.Controls.ChildGridControls;
    using SmartSoft.Invoices;
    using SmartSoft.Properties;
    using SmartSoft.ADP;
    using Stimulsoft.Report;
    using Stimulsoft.Report.Render;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Globalization;
    using System.IO;
    using System.Windows.Forms;

    public class FormReportViewer : FormControl
    {
        private ToolStripButton btnClose;
        private ToolStripSplitButton btnCurrency;
        private ToolStripButton btnDeclare;
        private ToolStripButton btnDesign;
        private ToolStripButton btnEdit;
        private ToolStripButton btnExpress;
        private ToolStripButton btnFind;
        private ToolStripMenuItem btnForeign;
        private ToolStripMenuItem btnLocal;
        private ToolStripButton btnMake;
        private ToolStripButton btnPreview;
        private ToolStripButton btnPrint;
        private ToolStripButton btnSum;
        private IContainer components;
        private GridControl grdBrowser;
        private bool ib_CheckDetailMost;
        private bool ib_CrossTabReport;
        private int ii_CurrencyIndex;
        private object[][] is_ForeignColNames;
        private object[][] is_LocalColNames;
        private string is_ReportFile;
        private string is_ReportSerial;
        private string is_ReportTitle;
        private GridControl oGridBrowser;
        private DataTable oLocalTable;
        private StiReport oReport;
        private Stimulsoft.Report.Render.StiPreviewControl oStiPreviewControl;
        public SplitContainer rptContainer;
        private ToolStripSeparator tbrSep01;
        private ToolStripSeparator tbrSep02;
        private ToolStripSeparator tbrSep03;
        private ToolStripSeparator tbrSep04;
        private ToolStripSeparator tbrSep05;
        private ToolStripSeparator tbrSep06;
        private ToolStripSeparator tbrSep07;
        private ToolStripSeparator tbrSep08;
        private ToolStripSeparator tbrSep09;
        private ToolStripSeparator tbrSep10;
        private ToolStrip Toolbars;
        private ToolStripSeparator toolStripSeparator1;
        private TbarSearch txtSearch;

        public FormReportViewer()
        {
            this.InitializeComponent();
            if (!this.CrossTabReport)
            {
                this.DataGridBrowser = this.grdBrowser;
                this.DataGridBrowser.AutoGenerateColumns = false;
                this.OnGenerateColumns();
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btnDeclare_Click(object sender, EventArgs e)
        {
            this.OnDeclare();
        }

        private void btnDesign_Click(object sender, EventArgs e)
        {
            this.OnDesign();
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (this.CheckDetailMost)
            {
                this.OnEdit();
            }
            else
            {
                this.OnShowDetail();
            }
        }

        private void btnExpress_Click(object sender, EventArgs e)
        {
            this.OnExpression();
        }

        private void btnFind_Click(object sender, EventArgs e)
        {
            this.OnFind();
        }

        private void btnForeign_Click(object sender, EventArgs e)
        {
            this.CurrencyIndex = 1;
            this.btnCurrency.Text = this.btnForeign.Text;
        }

        private void btnLocal_Click(object sender, EventArgs e)
        {
            this.CurrencyIndex = 0;
            this.btnCurrency.Text = this.btnLocal.Text;
        }

        private void btnMake_Click(object sender, EventArgs e)
        {
            this.OnMakeReport();
        }

        private void btnPreview_Click(object sender, EventArgs e)
        {
            this.OnPrint(false);
        }

        private void btnPrint_Click(object sender, EventArgs e)
        {
            this.OnPrint(true);
        }

        private void btnSum_Click(object sender, EventArgs e)
        {
            this.OnSum();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void grdBrowser_DoubleClick(object sender, EventArgs e)
        {
            if (this.btnEdit.Enabled)
            {
                if (this.CheckDetailMost)
                {
                    this.OnEdit();
                }
                else
                {
                    this.OnShowDetail();
                }
            }
        }

        private void InitializeComponent()
        {
            this.Toolbars = new System.Windows.Forms.ToolStrip();
            this.btnMake = new System.Windows.Forms.ToolStripButton();
            this.tbrSep01 = new System.Windows.Forms.ToolStripSeparator();
            this.btnExpress = new System.Windows.Forms.ToolStripButton();
            this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
            this.btnDeclare = new System.Windows.Forms.ToolStripButton();
            this.tbrSep02 = new System.Windows.Forms.ToolStripSeparator();
            this.txtSearch = new SmartSoft.Controls.TbarSearch();
            this.tbrSep03 = new System.Windows.Forms.ToolStripSeparator();
            this.btnFind = new System.Windows.Forms.ToolStripButton();
            this.tbrSep04 = new System.Windows.Forms.ToolStripSeparator();
            this.btnSum = new System.Windows.Forms.ToolStripButton();
            this.tbrSep05 = new System.Windows.Forms.ToolStripSeparator();
            this.btnPreview = new System.Windows.Forms.ToolStripButton();
            this.btnPrint = new System.Windows.Forms.ToolStripButton();
            this.tbrSep06 = new System.Windows.Forms.ToolStripSeparator();
            this.btnDesign = new System.Windows.Forms.ToolStripButton();
            this.tbrSep07 = new System.Windows.Forms.ToolStripSeparator();
            this.btnEdit = new System.Windows.Forms.ToolStripButton();
            this.tbrSep08 = new System.Windows.Forms.ToolStripSeparator();
            this.btnCurrency = new System.Windows.Forms.ToolStripSplitButton();
            this.btnLocal = new System.Windows.Forms.ToolStripMenuItem();
            this.tbrSep10 = new System.Windows.Forms.ToolStripSeparator();
            this.btnForeign = new System.Windows.Forms.ToolStripMenuItem();
            this.tbrSep09 = new System.Windows.Forms.ToolStripSeparator();
            this.btnClose = new System.Windows.Forms.ToolStripButton();
            this.rptContainer = new System.Windows.Forms.SplitContainer();
            this.grdBrowser = new SmartSoft.Controls.GridControl();
            this.Toolbars.SuspendLayout();
            this.rptContainer.Panel2.SuspendLayout();
            this.rptContainer.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.grdBrowser)).BeginInit();
            this.SuspendLayout();
            // 
            // Toolbars
            // 
            this.Toolbars.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.btnMake,
            this.tbrSep01,
            this.btnExpress,
            this.toolStripSeparator1,
            this.btnDeclare,
            this.tbrSep02,
            this.txtSearch,
            this.tbrSep03,
            this.btnFind,
            this.tbrSep04,
            this.btnSum,
            this.tbrSep05,
            this.btnPreview,
            this.btnPrint,
            this.tbrSep06,
            this.btnDesign,
            this.tbrSep07,
            this.btnEdit,
            this.tbrSep08,
            this.btnCurrency,
            this.tbrSep09,
            this.btnClose});
            this.Toolbars.Location = new System.Drawing.Point(0, 0);
            this.Toolbars.Name = "Toolbars";
            this.Toolbars.Size = new System.Drawing.Size(794, 27);
            this.Toolbars.TabIndex = 0;
            this.Toolbars.Text = "Toolbars";
            // 
            // btnMake
            // 
            this.btnMake.Image = global::SmartSoft.Properties.Resources.MAKE;
            this.btnMake.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnMake.Name = "btnMake";
            this.btnMake.Size = new System.Drawing.Size(69, 24);
            this.btnMake.Text = "Báo cáo";
            this.btnMake.ToolTipText = "Lập báo cáo (Ctrl+Enter)";
            this.btnMake.Click += new System.EventHandler(this.btnMake_Click);
            // 
            // tbrSep01
            // 
            this.tbrSep01.Name = "tbrSep01";
            this.tbrSep01.Size = new System.Drawing.Size(6, 27);
            // 
            // btnExpress
            // 
            this.btnExpress.Image = global::SmartSoft.Properties.Resources.Sua32;
            this.btnExpress.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnExpress.Name = "btnExpress";
            this.btnExpress.Size = new System.Drawing.Size(76, 24);
            this.btnExpress.Text = "Điều kiện";
            this.btnExpress.ToolTipText = "Thêm điều kiện";
            this.btnExpress.Click += new System.EventHandler(this.btnExpress_Click);
            // 
            // toolStripSeparator1
            // 
            this.toolStripSeparator1.Name = "toolStripSeparator1";
            this.toolStripSeparator1.Size = new System.Drawing.Size(6, 27);
            // 
            // btnDeclare
            // 
            this.btnDeclare.Image = global::SmartSoft.Properties.Resources.DECLARE1;
            this.btnDeclare.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnDeclare.Name = "btnDeclare";
            this.btnDeclare.Size = new System.Drawing.Size(83, 24);
            this.btnDeclare.Text = "Công thức";
            this.btnDeclare.ToolTipText = "Khai báo công thức";
            this.btnDeclare.Click += new System.EventHandler(this.btnDeclare_Click);
            // 
            // tbrSep02
            // 
            this.tbrSep02.Name = "tbrSep02";
            this.tbrSep02.Size = new System.Drawing.Size(6, 27);
            // 
            // txtSearch
            // 
            this.txtSearch.Name = "txtSearch";
            this.txtSearch.Size = new System.Drawing.Size(100, 27);
            this.txtSearch.Text = "Tìm nhanh...";
            this.txtSearch.ToolTipText = "F4";
            // 
            // tbrSep03
            // 
            this.tbrSep03.Name = "tbrSep03";
            this.tbrSep03.Size = new System.Drawing.Size(6, 27);
            // 
            // btnFind
            // 
            this.btnFind.Image = global::SmartSoft.Properties.Resources.FIND;
            this.btnFind.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnFind.Name = "btnFind";
            this.btnFind.Size = new System.Drawing.Size(48, 24);
            this.btnFind.Text = "Tìm";
            this.btnFind.ToolTipText = "Tìm kiếm";
            this.btnFind.Click += new System.EventHandler(this.btnFind_Click);
            // 
            // tbrSep04
            // 
            this.tbrSep04.Name = "tbrSep04";
            this.tbrSep04.Size = new System.Drawing.Size(6, 27);
            // 
            // btnSum
            // 
            this.btnSum.Image = global::SmartSoft.Properties.Resources.SUM;
            this.btnSum.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None;
            this.btnSum.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnSum.Name = "btnSum";
            this.btnSum.Size = new System.Drawing.Size(59, 24);
            this.btnSum.Text = "Tổng";
            this.btnSum.ToolTipText = "Tổng cộng";
            this.btnSum.Click += new System.EventHandler(this.btnSum_Click);
            // 
            // tbrSep05
            // 
            this.tbrSep05.Name = "tbrSep05";
            this.tbrSep05.Size = new System.Drawing.Size(6, 27);
            // 
            // btnPreview
            // 
            this.btnPreview.Image = global::SmartSoft.Properties.Resources.PREVIEW1;
            this.btnPreview.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnPreview.Name = "btnPreview";
            this.btnPreview.Size = new System.Drawing.Size(51, 24);
            this.btnPreview.Text = "Xem";
            this.btnPreview.ToolTipText = "Xem trước khi in (Ctrl+F7)";
            this.btnPreview.Click += new System.EventHandler(this.btnPreview_Click);
            // 
            // btnPrint
            // 
            this.btnPrint.Image = global::SmartSoft.Properties.Resources.PRINT11;
            this.btnPrint.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnPrint.Name = "btnPrint";
            this.btnPrint.Size = new System.Drawing.Size(37, 24);
            this.btnPrint.Text = "In";
            this.btnPrint.ToolTipText = "In (F7)";
            this.btnPrint.Click += new System.EventHandler(this.btnPrint_Click);
            // 
            // tbrSep06
            // 
            this.tbrSep06.Name = "tbrSep06";
            this.tbrSep06.Size = new System.Drawing.Size(6, 27);
            // 
            // btnDesign
            // 
            this.btnDesign.Image = global::SmartSoft.Properties.Resources.DESIGN2;
            this.btnDesign.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnDesign.Name = "btnDesign";
            this.btnDesign.Size = new System.Drawing.Size(46, 24);
            this.btnDesign.Text = "Sửa";
            this.btnDesign.ToolTipText = "Sửa mẫu báo cáo (Ctrl+F3)";
            this.btnDesign.Click += new System.EventHandler(this.btnDesign_Click);
            // 
            // tbrSep07
            // 
            this.tbrSep07.Name = "tbrSep07";
            this.tbrSep07.Size = new System.Drawing.Size(6, 27);
            // 
            // btnEdit
            // 
            this.btnEdit.Image = global::SmartSoft.Properties.Resources.EDIT1;
            this.btnEdit.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnEdit.Name = "btnEdit";
            this.btnEdit.Size = new System.Drawing.Size(71, 24);
            this.btnEdit.Text = "Sửa C.từ";
            this.btnEdit.ToolTipText = "Sửa chứng từ (F3)";
            this.btnEdit.Click += new System.EventHandler(this.btnEdit_Click);
            // 
            // tbrSep08
            // 
            this.tbrSep08.Name = "tbrSep08";
            this.tbrSep08.Size = new System.Drawing.Size(6, 27);
            // 
            // btnCurrency
            // 
            this.btnCurrency.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
            this.btnCurrency.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.btnLocal,
            this.tbrSep10,
            this.btnForeign});
            this.btnCurrency.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnCurrency.Name = "btnCurrency";
            this.btnCurrency.Size = new System.Drawing.Size(55, 19);
            this.btnCurrency.Text = "Nội tệ";
            this.btnCurrency.ToolTipText = "Loại tiền";
            // 
            // btnLocal
            // 
            this.btnLocal.Name = "btnLocal";
            this.btnLocal.Size = new System.Drawing.Size(152, 22);
            this.btnLocal.Text = "Nội tệ";
            this.btnLocal.Click += new System.EventHandler(this.btnLocal_Click);
            // 
            // tbrSep10
            // 
            this.tbrSep10.Name = "tbrSep10";
            this.tbrSep10.Size = new System.Drawing.Size(149, 6);
            // 
            // btnForeign
            // 
            this.btnForeign.Name = "btnForeign";
            this.btnForeign.Size = new System.Drawing.Size(152, 22);
            this.btnForeign.Text = "Ngoại tệ";
            this.btnForeign.Click += new System.EventHandler(this.btnForeign_Click);
            // 
            // tbrSep09
            // 
            this.tbrSep09.Name = "tbrSep09";
            this.tbrSep09.Size = new System.Drawing.Size(6, 27);
            // 
            // btnClose
            // 
            this.btnClose.Image = global::SmartSoft.Properties.Resources.CLOSE;
            this.btnClose.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnClose.Name = "btnClose";
            this.btnClose.Size = new System.Drawing.Size(58, 20);
            this.btnClose.Text = "Thoát";
            this.btnClose.ToolTipText = "Thoát (Esc)";
            this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
            // 
            // rptContainer
            // 
            this.rptContainer.Dock = System.Windows.Forms.DockStyle.Fill;
            this.rptContainer.FixedPanel = System.Windows.Forms.FixedPanel.Panel1;
            this.rptContainer.IsSplitterFixed = true;
            this.rptContainer.Location = new System.Drawing.Point(0, 27);
            this.rptContainer.Name = "rptContainer";
            this.rptContainer.Orientation = System.Windows.Forms.Orientation.Horizontal;
            // 
            // rptContainer.Panel2
            // 
            this.rptContainer.Panel2.Controls.Add(this.grdBrowser);
            this.rptContainer.Size = new System.Drawing.Size(794, 512);
            this.rptContainer.SplitterDistance = 104;
            this.rptContainer.SplitterWidth = 1;
            this.rptContainer.TabIndex = 2;
            // 
            // grdBrowser
            // 
            this.grdBrowser.AllowUserToAddRows = false;
            this.grdBrowser.AllowUserToDeleteRows = false;
            this.grdBrowser.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.DisplayedCells;
            this.grdBrowser.CheckColor = false;
            this.grdBrowser.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.grdBrowser.Dock = System.Windows.Forms.DockStyle.Fill;
            this.grdBrowser.Font = new System.Drawing.Font("Arial", 8.25F);
            this.grdBrowser.Location = new System.Drawing.Point(0, 0);
            this.grdBrowser.Name = "grdBrowser";
            this.grdBrowser.ReadOnly = true;
            this.grdBrowser.Size = new System.Drawing.Size(794, 407);
            this.grdBrowser.TabIndex = 0;
            this.grdBrowser.DoubleClick += new System.EventHandler(this.grdBrowser_DoubleClick);
            // 
            // FormReportViewer
            // 
            this.ClientSize = new System.Drawing.Size(794, 539);
            this.Controls.Add(this.rptContainer);
            this.Controls.Add(this.Toolbars);
            this.MinimumSize = new System.Drawing.Size(802, 566);
            this.Name = "FormReportViewer";
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            this.Toolbars.ResumeLayout(false);
            this.Toolbars.PerformLayout();
            this.rptContainer.Panel2.ResumeLayout(false);
            this.rptContainer.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.grdBrowser)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        protected virtual void OnDeclare()
        {
        }

        protected virtual void OnDesign()
        {
            if (!AppInstance.CheckTrialVersion && (this.StimulReport != null))
            {
                if (this.CurrencyIndex == 0)
                {
                    this.StimulReport.Load(AppInstance.UserReportPath + this.ReportFile + ".mrt");
                }
                else
                {
                    this.StimulReport.Load(AppInstance.UserReportPath + this.ReportFile + "F.mrt");
                }
                this.StimulReport.Design();
                this.StimulReport = null;
            }
        }

        protected virtual void OnEdit()
        {
            if ((((this.LocalTable != null) && this.LocalTable.Columns.Contains("Stt")) && (this.LocalTable.Columns.Contains("Ma_Ct") && (this.DataGridBrowser != null))) && ((this.DataGridBrowser.CurrentRow != null) && (this.DataGridBrowser.CurrentRow.DataBoundItem != null)))
            {
                DataRow row = ((DataRowView) this.DataGridBrowser.CurrentRow.DataBoundItem).Row;
                string str = row["Ma_Ct"].ToString();
                string str2 = row["Stt"].ToString();
                if (!string.IsNullOrEmpty(str) && !string.IsNullOrEmpty(str2))
                {
                    FormEditor editor11;
                    string str3 = SSDataAccess.SelectDataRow(false, "DMCT", "Ma_Ct", str, null)["Ma_Ls"].ToString();
                    switch (str3)
                    {
                        case "K":
                            new FormCTKTEditor(str, str2).Show();
                            return;

                        case "M":
                            //new FormCTMHEditor(str, str2).Show();
                            return;

                        case "B":
                            //new FormCTBHEditor(str, str2).Show();
                            return;

                        case "Q":
                            //new FormCTBGEditor(str, str2).Show();
                            return;

                        case "D":
                            //new FormCTDHEditor(str, str2).Show();
                            return;

                        case "N":
                            new FormCTNXEditor(str, str2).Show();
                            return;

                        case "Y":
                            //new FormCTYCMEditor(str, str2).Show();
                            return;

                        case "W":
                            new FormCTKHOEditor(str, str2).Show();
                            return;
                        case "X":
                            new FormCTKKEditor(str, str2).Show();
                            return;

                        case "P":
                            //new FormCTTPEditor(str, str2).Show();
                            return;

                        case "S":
                            //new FormCTSXEditor(str, str2).Show();
                            return;

                        case "O":
                            editor11 = new FormCTNBEditor(str, str2);
                            editor11.Show();
                            break;
                    }
                    if (str3 == "O")
                    {
                        editor11 = new FormCTNBEditor(str, str2);
                        editor11.Show();
                    }
                    else
                    {
                        bool flag1 = str3 == "T";
                    }
                }
            }
        }

        protected virtual void OnExpression()
        {
        }

        protected virtual void OnFind()
        {
        }

        protected virtual void OnGenerateColumns()
        {
            object[][] objArray = (this.CurrencyIndex == 0) ? this.LocalColNames : this.ForeignColNames;
            if ((objArray != null) && (objArray.GetLength(0) != 0))
            {
                this.DataGridBrowser.Columns.Clear();
                for (int i = 0; i < objArray.GetLength(0); i++)
                {
                    if (((string) objArray[i][2]) == "C")
                    {
                        DataGridViewTextBoxColumn dataGridViewColumn = new DataGridViewTextBoxColumn();
                        dataGridViewColumn.DataPropertyName = (string) objArray[i][0];
                        dataGridViewColumn.HeaderText = (string) objArray[i][1];
                        dataGridViewColumn.HeaderCell = new HeaderControl(dataGridViewColumn.HeaderCell);
                        this.DataGridBrowser.Columns.Add(dataGridViewColumn);
                    }
                    else if (((string) objArray[i][2]) == "D")
                    {
                        DataGridViewTextBoxColumn column2 = new DataGridViewTextBoxColumn();
                        column2.DataPropertyName = (string) objArray[i][0];
                        column2.HeaderText = (string) objArray[i][1];
                        column2.HeaderCell = new HeaderControl(column2.HeaderCell);
                        this.DataGridBrowser.Columns.Add(column2);
                    }
                    else if (((string) objArray[i][2]) == "N")
                    {
                        NumericColumn column3 = new NumericColumn();
                        column3.DataPropertyName = (string) objArray[i][0];
                        column3.HeaderText = (string) objArray[i][1];
                        column3.ZeroIsShown = false;
                        if (objArray[i][3] != null)
                        {
                            column3.UserTextNumericFormat = (AppInstance.TextNumericFormat) objArray[i][3];
                        }
                        else
                        {
                            column3.NumericPrecision = 10;
                            column3.NumericScaleOnFocus = 2;
                            column3.NumericScaleOnLostFocus = 2;
                        }
                        column3.HeaderCell = new HeaderControl(column3.HeaderCell);
                        this.DataGridBrowser.Columns.Add(column3);
                    }
                }
            }
        }

        protected virtual void OnMakeReport()
        {
            if ((this.CrossTabReport && (this.StimulReport != null)) && (this.LocalTable != null))
            {
                this.StimulReport.DataStore.Clear();
                this.StimulReport.RegData(this.ReportFile, this.LocalTable);
                this.UpdateParameters();
                this.OnSendParameters();
                Application.DoEvents();
                this.StimulReport.Render(true);
                this.StiPreviewControl.Report = this.StimulReport;
                this.StiPreviewControl.FirstPage();
            }
        }

        protected virtual void OnPrint(bool pb_Printed)
        {
            if (this.StimulReport != null)
            {
                if (this.LocalTable != null)
                {
                    this.StimulReport.DataStore.Clear();
                    this.StimulReport.RegData(this.ReportFile, this.LocalTable);
                    this.UpdateParameters();
                    this.OnSendParameters();
                }
                Application.DoEvents();
                if (pb_Printed)
                {
                    this.StimulReport.Print();
                }
                else
                {
                    this.StimulReport.Show();
                }
            }
        }

        protected virtual void OnSendParameters()
        {
        }

        protected virtual void OnShowDetail()
        {
        }

        protected virtual void OnSum()
        {
            if (base.ActiveGridBrowser == null) return;
            if (((base.ActiveGridBrowser != null) || (base.ActiveGridBrowser.CurrentCell != null)) && ((((base.ActiveGridBrowser.SelectedCells.Count != 1) || (base.ActiveGridBrowser.CurrentCell.ValueType.ToString() == "System.Decimal")) || ((base.ActiveGridBrowser.CurrentCell.ValueType.ToString() == "System.Int") || (base.ActiveGridBrowser.CurrentCell.ValueType.ToString() == "System.Int16"))) || (((base.ActiveGridBrowser.CurrentCell.ValueType.ToString() == "System.Int32") || (base.ActiveGridBrowser.CurrentCell.ValueType.ToString() == "System.Int64")) || (base.ActiveGridBrowser.CurrentCell.ValueType.ToString() == "System.Int16"))))
            {
                decimal num = 0M;
                int numericScaleOnFocus = 0;
                if (base.ActiveGridBrowser.Columns[base.ActiveGridBrowser.CurrentCell.ColumnIndex] is NumericColumn)
                {
                    numericScaleOnFocus = (base.ActiveGridBrowser.Columns[base.ActiveGridBrowser.CurrentCell.ColumnIndex] as NumericColumn).NumericScaleOnFocus;
                }
                if (base.ActiveGridBrowser.SelectedCells.Count == 1)
                {
                    for (int i = 0; i < base.ActiveGridBrowser.Rows.Count; i++)
                    {
                        DataGridViewCell cell = base.ActiveGridBrowser[base.ActiveGridBrowser.CurrentCell.ColumnIndex, i];
                        if (!cell.Value.Equals(DBNull.Value) && cell.Value.Equals(SDBNull.Value))
                        {
                            num += (decimal)cell.Value;
                        }
                    }
                }
                else
                {
                    foreach (DataGridViewCell cell2 in base.ActiveGridBrowser.SelectedCells)
                    {
                        if (!cell2.Value.Equals(DBNull.Value) && cell2.Value.Equals(SDBNull.Value) && ((((cell2.ValueType.ToString() == "System.Decimal") || (cell2.ValueType.ToString() == "System.Int")) || ((cell2.ValueType.ToString() == "System.Int16") || (cell2.ValueType.ToString() == "System.Int32"))) || ((cell2.ValueType.ToString() == "System.Int64") || (cell2.ValueType.ToString() == "System.Int16"))))
                        {
                            num += (decimal) cell2.Value;
                        }
                    }
                }
                MessageBox.Show("Tổng cộng: " + num.ToString("N" + numericScaleOnFocus.ToString()), AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if ((keyData == (Keys.Control | Keys.Return)) && this.btnMake.Enabled)
            {
                this.OnMakeReport();
                return true;
            }
            if (keyData == Keys.F4)
            {
                this.txtSearch.Focus();
                return true;
            }
            if ((keyData == Keys.F3) && this.btnEdit.Enabled)
            {
                if (this.CheckDetailMost)
                {
                    this.OnEdit();
                }
                else
                {
                    this.OnShowDetail();
                }
                return true;
            }
            if ((keyData == (Keys.Control | Keys.F)) && this.btnFind.Enabled)
            {
                this.OnFind();
                return true;
            }
            if ((keyData == (Keys.Control | Keys.F3)) && this.btnDesign.Enabled)
            {
                this.OnDesign();
                return true;
            }
            if ((keyData == Keys.F7) && this.btnPrint.Enabled)
            {
                this.OnPrint(true);
                return true;
            }
            if ((keyData == (Keys.Control | Keys.F7)) && this.btnPreview.Enabled)
            {
                this.OnPrint(false);
                return true;
            }
            if ((keyData == Keys.Escape) && this.btnClose.Enabled)
            {
                base.Close();
                return true;
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }

        protected virtual void UpdateParameters()
        {
            if (this.StimulReport != null)
            {
                if (this.CurrencyIndex == 0)
                {
                    this.StimulReport.Load(AppInstance.UserReportPath + this.ReportFile + ".mrt");
                }
                else
                {
                    this.StimulReport.Load(AppInstance.UserReportPath + this.ReportFile + "F.mrt");
                }
                this.StimulReport.Compile();

                this.StimulReport["DEMOString"] = AppInstance.DEMOString;
                this.StimulReport["DatePrinted"] = (AppInstance.ShowDateTime == 2) || (AppInstance.ShowDateTime == 3);
                this.StimulReport["ReportTitle"] = this.ReportTitle.ToUpper();
                this.StimulReport["CompanyName"] = AppInstance.NameOfEnterprise;
                this.StimulReport["CompanyAddress"] = AppInstance.AddressOfEnterprise;
                this.StimulReport["DecimalSymbol"] = NumberFormatInfo.CurrentInfo.NumberDecimalSeparator;
                this.StimulReport["GroupingSymbol"] = NumberFormatInfo.CurrentInfo.NumberGroupSeparator;
                this.StimulReport["PSo_Luong_Decim"] = AppInstance.QuantityDecimals;
                this.StimulReport["PSo_LuongDM_Decim"] = AppInstance.NormQuantity;
                this.StimulReport["PSo_LuongHS_Decim"] = AppInstance.RatioFormat;
                this.StimulReport["NegativePattern"] = NumberFormatInfo.CurrentInfo.NumberNegativePattern;
                this.StimulReport["PGia_Decim"] = AppInstance.LCPriceDecimals;
                this.StimulReport["PGia_Nt_Decim"] = AppInstance.FCPriceDecimals;
                this.StimulReport["PTy_Gia_Decim"] = AppInstance.ExchangeFormat;
                this.StimulReport["PTien_Decim"] = AppInstance.LCAmountDecimals;
                this.StimulReport["PTien_Nt_Decim"] = AppInstance.FCAmountDecimals;
                if (!string.IsNullOrEmpty(this.ReportSerial))
                {
                    this.StimulReport["TheDecisionNumber"] = "Mẫu số: " + this.ReportSerial;
                    if (this.ReportSerial.Trim().ToUpper().Substring(0, 4) != "SKEY")
                    {
                        this.StimulReport["TheFirstRowDecision"] = AppInstance.FirstRowReport;
                        this.StimulReport["TheSecondRowDecision"] = AppInstance.SecondRowReport;
                        this.StimulReport["TheThirdRowDecision"] = AppInstance.ThirdRowReport;
                    }
                }
            }
        }

        [DefaultValue(false)]
        public bool CheckDetailMost
        {
            get
            {
                return this.ib_CheckDetailMost;
            }
            set
            {
                if (this.ib_CheckDetailMost != value)
                {
                    this.ib_CheckDetailMost = value;
                }
            }
        }

        public bool CrossTabReport
        {
            get
            {
                return this.ib_CrossTabReport;
            }
            set
            {
                if (this.ib_CrossTabReport != value)
                {
                    this.ib_CrossTabReport = value;
                    if (this.ib_CrossTabReport)
                    {
                        this.btnFind.Visible = false;
                        this.tbrSep04.Visible = false;
                        this.btnSum.Visible = false;
                        this.tbrSep05.Visible = false;
                        this.btnPreview.Visible = false;
                        this.btnPrint.Visible = false;
                        this.tbrSep06.Visible = false;
                        this.btnEdit.Visible = false;
                        this.tbrSep08.Visible = false;
                        this.grdBrowser.Visible = false;
                        this.StiPreviewControl.ShowCloseButton = false;
                        this.StiPreviewControl.ShowBookmarksPanel = false;
                        this.StiPreviewControl.Visible = true;
                    }
                }
            }
        }

        public int CurrencyIndex
        {
            get
            {
                return this.ii_CurrencyIndex;
            }
            set
            {
                if (this.ii_CurrencyIndex != value)
                {
                    this.ii_CurrencyIndex = value;
                }
            }
        }

        public GridControl DataGridBrowser
        {
            get
            {
                return this.oGridBrowser;
            }
            set
            {
                if (this.oGridBrowser != value)
                {
                    this.oGridBrowser = value;
                }
            }
        }

        [Browsable(false)]
        public object[][] ForeignColNames
        {
            get
            {
                return this.is_ForeignColNames;
            }
            set
            {
                this.is_ForeignColNames = value;
            }
        }

        [Browsable(false)]
        public object[][] LocalColNames
        {
            get
            {
                return this.is_LocalColNames;
            }
            set
            {
                this.is_LocalColNames = value;
            }
        }

        public DataTable LocalTable
        {
            get
            {
                return this.oLocalTable;
            }
            set
            {
                if (this.oLocalTable != value)
                {
                    this.oLocalTable = value;
                    if (!this.CrossTabReport)
                    {
                        this.DataGridBrowser.DataSource = new BindingSource(this.LocalTable, this.LocalTable.TableName);
                    }
                }
            }
        }

        public string ReportFile
        {
            get
            {
                return this.is_ReportFile;
            }
            set
            {
                if (this.is_ReportFile != value)
                {
                    this.is_ReportFile = value;
                }
            }
        }

        public string ReportSerial
        {
            get
            {
                return this.is_ReportSerial;
            }
            set
            {
                if (this.is_ReportSerial != value)
                {
                    this.is_ReportSerial = value;
                }
            }
        }

        public string ReportTitle
        {
            get
            {
                return this.is_ReportTitle;
            }
            set
            {
                if (this.is_ReportTitle != value)
                {
                    this.is_ReportTitle = value;
                }
            }
        }

        public StiReport StimulReport
        {
            get
            {
                if (string.IsNullOrEmpty(this.ReportFile) || !File.Exists(AppInstance.UserReportPath + this.ReportFile + ".mrt"))
                {
                    return null;
                }
                if (this.oReport == null)
                {
                    this.oReport = new StiReport();
                }
                return this.oReport;
            }
            set
            {
                if (this.oReport != value)
                {
                    this.oReport = value;
                }
            }
        }

        public Stimulsoft.Report.Render.StiPreviewControl StiPreviewControl
        {
            get
            {
                if (this.oStiPreviewControl == null)
                {
                    this.oStiPreviewControl = new Stimulsoft.Report.Render.StiPreviewControl();
                    this.oStiPreviewControl.Dock = DockStyle.Fill;
                    this.rptContainer.Panel2.Controls.Add(this.oStiPreviewControl);
                }
                return this.oStiPreviewControl;
            }
        }

        public string TitleText
        {
            set
            {
                this.Text = value;
            }
        }
    }
}

